package Client;

import java.awt.*;
import java.awt.event.KeyEvent;

public class Player {

	private int health = 100;
	private Point absoluteLocation = new Point(0, 0);
	private String name = "Player";
	private int id = -1;
	private int speed = 2;
	private int latency = -1;
	private double angle = -1;
	private long lastLatencyGet = System.currentTimeMillis();
	private EaTGClient parent = null;

	public Player(EaTGClient eatg, int ide, String nam, Point loc) {
		name = nam;
		absoluteLocation = loc;
		id = ide;
		parent = eatg;
	}

	public int getHealth() {
		return health;
	}

	public Point getScreenLoc() {
		return new Point(absoluteLocation.x + parent.th.mapStart.x, absoluteLocation.y
				+ parent.th.mapStart.y);
	}

	public Point getAbsoluteLoc() {
		return absoluteLocation;
	}

	public String getName() {
		return name;
	}

	public int getId() {
		return id;
	}

	public int getLatency() {
		return latency;
	}

	public double getAngle() {
		return angle;
	}

	public void setAngle(double angle2) {
		angle = angle2;
	}

	public void setLatency(int l) {
		latency = l;
		lastLatencyGet = System.currentTimeMillis();
	}

	public boolean getDestroy() {
		return (lastLatencyGet < System.currentTimeMillis() - 2000);
	}

	public void setLoc(Point newl) {
		absoluteLocation.setLocation(newl);
	}

	public void moveDetect(int code) {
		switch (code) {
		case KeyEvent.VK_UP:
			absoluteLocation.setLocation(absoluteLocation.x, absoluteLocation.y -= speed);
			break;
		case KeyEvent.VK_DOWN:
			absoluteLocation.setLocation(absoluteLocation.x, absoluteLocation.y += speed);
			break;
		case KeyEvent.VK_RIGHT:
			absoluteLocation.setLocation(absoluteLocation.x += speed, absoluteLocation.y);
			break;
		case KeyEvent.VK_LEFT:
			absoluteLocation.setLocation(absoluteLocation.x -= speed, absoluteLocation.y);
			break;
		}
		System.out.println(absoluteLocation);
	}

	public void getTileAtLoc(int x, int y) {

	}

	public Ammo getAmmoDetails() {
		Ammo ta = new Ammo();
		ta.setStartLoc(absoluteLocation);
		ta.setAngle(angle);
		ta.setType(1);
		return ta;
	}
}